<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Requesthandler extends CI_Controller {

		
	public function index()
	{
		show_404();
	}
	
	public function verifylogin()
	{

		if(isset($_POST['email']) || isset($_POST['password'])){
			$response = $this->verifier_model->verify_login($_POST['email'],$_POST['password']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode(""));
		}
		
	}
	
	public function checkemail()
	{

		if(isset($_POST['email'])){
			$response = $this->verifier_model->verify_email($_POST['email']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function searchstudent()
	{
		if( isset($_POST['name']) || isset($_POST['student_id']) || isset($_POST['school_year'])){
			$response = $this->search_model->searchStudent( trim($_POST['name']) ,trim($_POST['student_id']),trim($_POST['school_year']));
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function gettaggedstudents()
	{
		if( isset($_POST['guardian_id'])){
			$response = $this->search_model->searchStudentByGuardianID( trim($_POST['guardian_id']));
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function searchguardian()
	{
		if( isset($_POST['name'])){
			$response = $this->search_model->searchGuardian( trim($_POST['name']));
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}
	
	public function getguardianid()
	{
		if( isset($_POST['account_id'])){
			$response = $this->search_model->getGuardianID($_POST['account_id']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
	}
	
	public function fillstudent()
	{
		if(	isset($_POST['id'])){
			$response = $this->search_model->searchStudentByID( trim($_POST['id']));
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function updatestudent()
	{
		if(	isset($_POST['data'])){
			$response = $this->connection_model->updateStudent($_POST['data']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function deletestudent()
	{
		if(	isset($_POST['id'])){
			$response = $this->connection_model->deleteStudent($_POST['id']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function fillguardian()
	{
		if(	isset($_POST['id'])){
			$response = $this->search_model->searchGuardianByID( trim($_POST['id']));
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function updateguardian()
	{
		if(	isset($_POST['data'])){
			$response = $this->connection_model->updateGuardian($_POST['data']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function deleteguardian()
	{
		if(	isset($_POST['id'])){
			$response = $this->connection_model->deleteGuardian($_POST['id']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function addguardianaccount()
	{
		if(	isset($_POST['guardian']) && isset($_POST['accountDetails'])){
			$response = $this->connection_model->addGuardianAccount($_POST['accountDetails'],$_POST['guardian']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}
	
	public function addstudent()
	{
		if(	isset($_POST['data'])){
			$response = $this->connection_model->addStudent($_POST['data']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
		
	}

	public function requestencrpytion(){
		if(	isset($_POST['data'])){
			$response 	=	md5($_POST['data']);
			$this->output->set_content_type('application/json')->set_output(json_encode($response));
		}else{
			$this->output->set_content_type('application/json')->set_output(json_encode("Controller Error: NO POST DATA"));
		}
	}
}